package edu.hunau.cxb19.oop.class29;

import jdk.nashorn.api.tree.ForInLoopTree;

/**
 *
 * @author hb
 *
 *         2020-04-09 15:28:08
 */
public class ThreadTest {
	public static void main(String[] args) {
		 //实例化一个线程
		MyThread t1 = new MyThread("my-thread-01");
		//启动线程
		t1.start();
		
		Thread t2=new Thread("my-thread-02") {
			public void run() {
				for (int i = 0; i < 100; i++) {
					System.out.println("\t\t"+this.getName()+":"+i);
				}
			} 
		};
		t2.start();
		
		Thread t3=new Thread(()->{
 				for (int i = 0; i < 100; i++) {
					System.out.println("\t\t\t my-thread-03"+":"+i);
				}
			},"my-thread-03");
		t3.start();
		t3.start();
}}

//为Thread提供一个子类
class MyThread extends Thread {
	public MyThread(String name) {
		super(name);// Thread(name)
	}

	/**
	 * 重写run方法实现线程体
	 */
	public void run() {
		for (int i = 0; i < 100; i++) {
			System.out.println("\t my-thread:" + i);
		}

	}
}